<?php 
use Wdl\helper\webHelper;
/**
 * 管理客户的委托信息
 */
 
 defined('IN_IA') or exit('Access Denied');
 global $_GPC, $_W;
 load()->func('tpl'); 
 $uniacid = webHelper::bindUniacid(); 
 $openid = $_W['openid'];
 $operation = !empty($_GPC['op']) ? $_GPC['op'] : 'chushou';	

$template_name = sprintf("sdemand/display",  $operation);
 
if($operation == 'setproperty'){
    $id = intval($_GPC['id']);
    $field = trim($_GPC['type']);
    $data = intval($_GPC['data']);
    $value = $data ==1 ? 0 :1;
    pdo_update("kbwdl_demand", [$field =>  $value,'feed_time'=> TIMESTAMP], ['id'=> $id,'uniacid' => $uniacid]);
    die(json_encode(array("result" => 1, "data" => $value)));
}
   /*分页处理*/
   /*删除门店成功*/
       if(!empty($_GPC['id'])){
        $params = array(':uniacid' => $uniacid,':id'=> intval($_GPC['id']) );
        pdo_query("delete  from  ".tablename('kbwdl_demand') ."  where uniacid=:uniacid and id=:id", $params);
        message("删除操作成功", $this->createWebUrl('sdemand',['op'=> $operation]), 'success');
    }
 
   $condition = ' WHERE `uniacid` = :uniacid AND send_type=:send_type ';
   $params = array('uniacid' => $uniacid ,'send_type'=> $operation);
   if (!empty($_GPC['keyword'])) {
           $condition .= ' AND (`nickname` LIKE :keyword OR mobile LIKE :keyword OR village like :keyword)';
           $params[':keyword'] = '%' . trim($_GPC['keyword']) . '%';
   } 
   //获取列表数据
    $fd = webHelper::table_list_data('kbwdl_demand',$condition, $params);
    $total = $fd['total'];
    $list  = $fd['list'];
    $pager = $fd['pager'];

 
$submenus = [    
    'chushou'=> ['name'=> '出售委托', 'do'=> 'sdemand'],
    'chuzu'=> ['name'=> '出租委托', 'do'=> 'sdemand'],
    'qiugou'=> ['name'=> '求购房源', 'do'=> 'sdemand'],
    'qiuzu'=> ['name'=> '求租房源', 'do'=> 'sdemand'],
];
include $this->template('sdemand/layout');